package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TProductReview;
import com.ruoyi.business.service.ITProductReviewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品评价Controller
 * 
 * @author laoguo
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/business/review")
public class TProductReviewController extends BaseController
{
    @Autowired
    private ITProductReviewService tProductReviewService;

    /**
     * 查询商品评价列表
     */
    @PreAuthorize("@ss.hasPermi('business:review:list')")
    @GetMapping("/list")
    public TableDataInfo list(TProductReview tProductReview)
    {
        startPage();
        List<TProductReview> list = tProductReviewService.selectTProductReviewList(tProductReview);
        return getDataTable(list);
    }

    /**
     * 导出商品评价列表
     */
    @PreAuthorize("@ss.hasPermi('business:review:export')")
    @Log(title = "商品评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TProductReview tProductReview)
    {
        List<TProductReview> list = tProductReviewService.selectTProductReviewList(tProductReview);
        ExcelUtil<TProductReview> util = new ExcelUtil<TProductReview>(TProductReview.class);
        util.exportExcel(response, list, "商品评价数据");
    }

    /**
     * 获取商品评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:review:query')")
    @GetMapping(value = "/{reviewId}")
    public AjaxResult getInfo(@PathVariable("reviewId") Long reviewId)
    {
        return success(tProductReviewService.selectTProductReviewByReviewId(reviewId));
    }

    /**
     * 新增商品评价
     */
    @PreAuthorize("@ss.hasPermi('business:review:add')")
    @Log(title = "商品评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProductReview tProductReview)
    {
        return toAjax(tProductReviewService.insertTProductReview(tProductReview));
    }

    /**
     * 修改商品评价
     */
    @PreAuthorize("@ss.hasPermi('business:review:edit')")
    @Log(title = "商品评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProductReview tProductReview)
    {
        return toAjax(tProductReviewService.updateTProductReview(tProductReview));
    }

    /**
     * 删除商品评价
     */
    @PreAuthorize("@ss.hasPermi('business:review:remove')")
    @Log(title = "商品评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reviewIds}")
    public AjaxResult remove(@PathVariable Long[] reviewIds)
    {
        return toAjax(tProductReviewService.deleteTProductReviewByReviewIds(reviewIds));
    }
}
